package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.baiwei.BaiweiScore;
import com.ucredit.babel.common.model.baiwei.BaiweiScorePlusRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百维信用分 Plus
 * @author szw
 *
 */
public class BaiweiScorePlusParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     *
     *百维信用分 Plus
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BaiweiScorePlusRecord obj= (BaiweiScorePlusRecord)model;
        BaiweiScore score = obj.getScore();

        StringBuilder sb = getBaseInfo(obj, successful);
        StringBuilder bwSb = new StringBuilder();

        bwSb.append(score.getStatus() == null ? "" : score.getStatus()).append(CRT001);
        bwSb.append(score.getCode() == null ? "" : score.getCode()).append(CRT001);
        bwSb.append(score.getMsg() == null ? "" : score.getMsg()).append(CRT001);
        bwSb.append(score.getCheckResult() == null ? "" : score.getCheckResult()).append(CRT001);
        bwSb.append(score.getScore() == null ? "" : score.getScore()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + bwSb.toString() + txSb.toString()).replace("\n","").replace("\r", " "));
        context.write(key,val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_baiwei_score_plus_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIWEI_SCORE_PLUS_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百维信用分 Plus";
    }
}
